<?php
/**
 * Created by PhpStorm.
 * User: zy
 * Date: 2017/11/30 0030
 * Time: 16:26
 */

//des加密解密
namespace app\tools;


class Encrypt
{
    //私钥和公钥不能动，一动就会报错
    private $publicKey = '-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzxUcEn55cGyBvRgeOzwP
3W1mUTJ7W6LJT4/SjtIhURscBfDxzd6kaAScJxblj8bxi8HdwdSZVXEHwSeO2vHD
tlxNP7LvwF4NwMr/cGHh5lLVu2T+LJdKqW/i8h50Hr9gPrcTrG0MRKstBmfUoW6e
/KFpsZwxyaJ11pgXbBOtm9BtKwpyYLZw/1tnxBdOwnQMTITcIYvpPsdPId0ZBR7+
iPqAfTYbOVEN4UH8ZcOcJfedxS3yCn6GKvHs4aWSznmdx1pFWwSPehqQYRhIBvAQ
9eyZ9w3fjET5wKNPpupoZGGX93spF1tj1fqAwJArJzKRn+cCjTCWLfE07A4l8INS
AwIDAQAB
-----END PUBLIC KEY-----';
    private $privateKey = '-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAzxUcEn55cGyBvRgeOzwP3W1mUTJ7W6LJT4/SjtIhURscBfDx
zd6kaAScJxblj8bxi8HdwdSZVXEHwSeO2vHDtlxNP7LvwF4NwMr/cGHh5lLVu2T+
LJdKqW/i8h50Hr9gPrcTrG0MRKstBmfUoW6e/KFpsZwxyaJ11pgXbBOtm9BtKwpy
YLZw/1tnxBdOwnQMTITcIYvpPsdPId0ZBR7+iPqAfTYbOVEN4UH8ZcOcJfedxS3y
Cn6GKvHs4aWSznmdx1pFWwSPehqQYRhIBvAQ9eyZ9w3fjET5wKNPpupoZGGX93sp
F1tj1fqAwJArJzKRn+cCjTCWLfE07A4l8INSAwIDAQABAoIBAAVUnsdfGBMrx98t
OsH9ls71XPfkG8bNFu+EXUAt6oui7gK9JAxPmd3PmJFtBnXAAkG9uM6fgV7wrOls
8kFyjb4o/BgSrBdAlIwM7axf6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DRy1
utHeG8HYWQLspAJOslKgowYlNW/1vH+0i4HfuWXPfzEdgmy8QPOz
-----END RSA PRIVATE KEY-----
';
    private $key = "8-a9%jx*&1dcf=-=/21ck";

    //解密是你那边使用的，在你的代码里面给私钥删除了
    function decrypt($encryptData){
        $decrypted = '';
        $encrypted = base64_decode($encryptData);
        openssl_public_decrypt($encrypted, $decrypted, $this->publicKey);
        return $decrypted;
    }

    //加密是我这边使用的
    function encrypt($originalData){
        $encrypted = '';
        openssl_private_encrypt($originalData, $encrypted, $this->privateKey);
        return base64_encode($encrypted);
    }
}